namespace sorochinska_kl.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Trainings : DbMigration
    {
        public override void Up()
        {
            RenameColumn(table: "dbo.UserSkill", name: "EmployeeID", newName: "UserId");
            CreateTable(
                "dbo.Trainings",
                c => new
                    {
                        TrainingID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Instructor = c.String(),
                        StartDate = c.DateTime(nullable: false),
                        EndDate = c.DateTime(nullable: false),
                        WayOfAttendance = c.String(),
                    })
                .PrimaryKey(t => t.TrainingID);
            
            CreateTable(
                "dbo.UserTrainings1",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        TrainingID = c.Int(nullable: false),
                        TestResult = c.Int(),
                    })
                .PrimaryKey(t => new { t.UserId, t.TrainingID });
            
            CreateTable(
                "dbo.UserTrainings",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        TrainingID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserId, t.TrainingID })
                .ForeignKey("dbo.Employees", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.Trainings", t => t.TrainingID, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.TrainingID);
            
            AlterColumn("dbo.Employees", "WorkPhone", c => c.String(maxLength: 13));
            AlterColumn("dbo.Employees", "CellPhone", c => c.String(maxLength: 13));
        }
        
        public override void Down()
        {
            DropIndex("dbo.UserTrainings", new[] { "TrainingID" });
            DropIndex("dbo.UserTrainings", new[] { "UserId" });
            DropForeignKey("dbo.UserTrainings", "TrainingID", "dbo.Trainings");
            DropForeignKey("dbo.UserTrainings", "UserId", "dbo.Employees");
            AlterColumn("dbo.Employees", "CellPhone", c => c.String());
            AlterColumn("dbo.Employees", "WorkPhone", c => c.String());
            DropTable("dbo.UserTrainings");
            DropTable("dbo.UserTrainings1");
            DropTable("dbo.Trainings");
            RenameColumn(table: "dbo.UserSkill", name: "UserId", newName: "EmployeeID");
        }
    }
}
